home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 121 / Computer Shopper 121 / Computer Shopper 121.iso / Internet / Demon / TURNPIKE.1 / CLASSES.ZIP / MS / APPLET / AppletPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  7.2 KB  |  367 lines

  1. package ms.applet;
  2.  
  3. import java.applet.Applet;
  4. import java.applet.AppletContext;
  5. import java.applet.AppletStub;
  6. import java.awt.BorderLayout;
  7. import java.awt.Component;
  8. import java.awt.Container;
  9. import java.awt.Dimension;
  10. import java.awt.Event;
  11. import java.awt.Panel;
  12. import java.io.IOException;
  13. import java.net.URL;
  14. import sun.misc.MessageUtils;
  15.  
  16. public abstract class AppletPanel extends Panel implements AppletStub, Runnable {
  17.    static String propName = "appletloader.";
  18.    Applet applet;
  19.    AppletClassLoader loader;
  20.    protected int status;
  21.    Thread handler;
  22.    public static final int APPLET_DISPOSE = 0;
  23.    public static final int APPLET_LOAD = 1;
  24.    public static final int APPLET_INIT = 2;
  25.    public static final int APPLET_START = 3;
  26.    public static final int APPLET_STOP = 4;
  27.    public static final int APPLET_DESTROY = 5;
  28.    public static final int APPLET_QUIT = 6;
  29.    public static final int APPLET_ERROR = 7;
  30.    public static final int APPLET_RESIZE = 51234;
  31.    public static final int APPLET_LOADING = 51235;
  32.    public static final int APPLET_LOADING_COMPLETED = 51236;
  33.    Dimension appletSize = new Dimension(100, 100);
  34.    // $FF: renamed from: mu sun.misc.MessageUtils
  35.    MessageUtils field_0 = new MessageUtils();
  36.    Thread loaderThread;
  37.    boolean loadAbortRequest = false;
  38.    AppletViewer mAppletViewer;
  39.    Event queue;
  40.    private AppletClassLoader mAppletClassLoader;
  41.  
  42.    public AppletPanel(AppletViewer var1) {
  43.       this.mAppletViewer = var1;
  44.    }
  45.  
  46.    public void init(AppletThreadGroup var1) {
  47.       ((Container)this).setLayout(new BorderLayout());
  48.       String var2 = this.getParameter("width");
  49.       if (var2 != null) {
  50.          Dimension var10000 = this.appletSize;
  51.          Integer var3 = new Integer(Integer.parseInt(var2, 10));
  52.          var10000.width = var3.value;
  53.       }
  54.  
  55.       var2 = this.getParameter("height");
  56.       if (var2 != null) {
  57.          Dimension var7 = this.appletSize;
  58.          Integer var5 = new Integer(Integer.parseInt(var2, 10));
  59.          var7.height = var5.value;
  60.       }
  61.  
  62.       String var6 = "applet-" + this.getParameter("code");
  63.       this.handler = new Thread(var1, this, "thread " + var6);
  64.       this.handler.start();
  65.    }
  66.  
  67.    public Dimension minimumSize() {
  68.       return new Dimension(this.appletSize.width, this.appletSize.height);
  69.    }
  70.  
  71.    public Dimension preferredSize() {
  72.       return this.minimumSize();
  73.    }
  74.  
  75.    public void sendEvent(int var1) {
  76.       this.sendEvent(new Event((Object)null, var1, (Object)null));
  77.    }
  78.  
  79.    protected synchronized void sendEvent(Event var1) {
  80.       if (this.queue == null) {
  81.          var1.target = this.queue;
  82.          this.queue = var1;
  83.          this.notifyAll();
  84.       } else {
  85.          Event var2;
  86.          for(var2 = this.queue; var2.target != null; var2 = (Event)var2.target) {
  87.          }
  88.  
  89.          var2.target = var1;
  90.       }
  91.    }
  92.  
  93.    synchronized Event getNextEvent() throws InterruptedException {
  94.       while(this.queue == null) {
  95.          this.wait(0L);
  96.       }
  97.  
  98.       Event var1 = this.queue;
  99.       this.queue = (Event)this.queue.target;
  100.       var1.target = this;
  101.       return var1;
  102.    }
  103.  
  104.    public void run() {
  105.       Thread var1 = Thread.currentThread();
  106.       if (var1 == this.loaderThread) {
  107.          this.runLoader();
  108.       } else {
  109.          int var2 = var1.priority;
  110.          var1.setPriority(var2 + 1);
  111.  
  112.          while(true) {
  113.             Event var3;
  114.             try {
  115.                var3 = this.getNextEvent();
  116.             } catch (InterruptedException var8) {
  117.                return;
  118.             }
  119.  
  120.             try {
  121.                switch (var3.id) {
  122.                   case 0:
  123.                      if (this.status == 1) {
  124.                         this.status = 0;
  125.                         ((Container)this).remove(this.applet);
  126.                      }
  127.                      break;
  128.                   case 1:
  129.                      if (this.okToLoad() && this.loaderThread == null) {
  130.                         this.setLoaderThread(new Thread(this));
  131.                         this.loaderThread.setPriority(var2 + 1);
  132.                         this.loaderThread.start();
  133.                         Thread var4 = this.loaderThread;
  134.                         var4.join(0L);
  135.                         this.setLoaderThread((Thread)null);
  136.                      }
  137.                      break;
  138.                   case 2:
  139.                      if (this.status == 1) {
  140.                         this.applet.resize(this.appletSize);
  141.                         this.applet.init();
  142.                         ((Container)this).validate();
  143.                         this.status = 2;
  144.                         this.showAppletStatus(System.getProperty(propName + "inited"));
  145.                      }
  146.                      break;
  147.                   case 3:
  148.                      if (this.status == 2) {
  149.                         this.applet.resize(this.appletSize);
  150.                         this.applet.start();
  151.                         ((Container)this).validate();
  152.                         this.applet.show();
  153.                         this.status = 3;
  154.                         this.showAppletStatus(System.getProperty(propName + "started"));
  155.                      }
  156.                      break;
  157.                   case 4:
  158.                      if (this.status == 3) {
  159.                         this.status = 2;
  160.                         this.applet.stop();
  161.                         this.showAppletStatus(System.getProperty(propName + "stopped"));
  162.                      }
  163.                      break;
  164.                   case 5:
  165.                      if (this.status == 2) {
  166.                         this.status = 1;
  167.                         this.applet.destroy();
  168.                      }
  169.                      break;
  170.                   case 6:
  171.                      return;
  172.                }
  173.             } catch (Exception var9) {
  174.                String var12 = propName + "exception2";
  175.                String var13 = var9.getClass().getName();
  176.                String var14 = ((Throwable)var9).getMessage();
  177.                this.showAppletStatus(MessageUtils.subst(System.getProperty(var12), var13, var14));
  178.                this.showAppletException(var9);
  179.             } catch (ThreadDeath var10) {
  180.                return;
  181.             } catch (Error var11) {
  182.                String var5 = propName + "error2";
  183.                String var6 = var11.getClass().getName();
  184.                String var7 = ((Throwable)var11).getMessage();
  185.                this.showAppletStatus(MessageUtils.subst(System.getProperty(var5), var6, var7));
  186.                this.showAppletException(var11);
  187.             }
  188.  
  189.             this.clearLoadAbortRequest();
  190.          }
  191.       }
  192.    }
  193.  
  194.    private void runLoader() {
  195.       if (this.status == 0) {
  196.          ((Component)this).postEvent(new Event(this, 51235, (Object)null));
  197.          this.status = 1;
  198.  
  199.          try {
  200.             this.loader = this.getClassLoader(this.getCodeBase());
  201.             if (Thread.currentThread().interruptRequested) {
  202.                this.status = 0;
  203.                ((Component)this).postEvent(new Event(this, 51236, (Object)null));
  204.                return;
  205.             }
  206.          } catch (IOException var22) {
  207.             this.status = 7;
  208.             this.showAppletStatus(((Throwable)var22).getMessage());
  209.             this.showAppletLog(((Throwable)var22).getMessage());
  210.             this.showAppletException(var22);
  211.             ((Component)this).postEvent(new Event(this, 51236, (Object)null));
  212.             return;
  213.          }
  214.  
  215.          String var1 = this.getParameter("code");
  216.          if (var1 == null) {
  217.             String var2 = propName + "nocode";
  218.             this.status = 7;
  219.             this.showAppletStatus(System.getProperty(var2));
  220.             this.showAppletLog(var2);
  221.             ((Component)this).repaint();
  222.          } else if (var1.startsWith(".class", var1.count - ".class".count)) {
  223.             var1 = var1.substring(0, var1.count - 6).replace('/', '.');
  224.          } else if (var1.startsWith(".java", var1.count - ".java".count)) {
  225.             var1 = var1.substring(0, var1.count - 5).replace('/', '.');
  226.          }
  227.  
  228.          label175: {
  229.             try {
  230.                String var4 = propName + "loading";
  231.                this.showAppletStatus(MessageUtils.subst(System.getProperty(var4), var1));
  232.                this.applet = (Applet)this.loader.loadClass(var1).newInstance();
  233.                if (!Thread.currentThread().interruptRequested) {
  234.                   break label175;
  235.                }
  236.  
  237.                this.status = 0;
  238.                this.applet = null;
  239.                return;
  240.             } catch (ClassNotFoundException var15) {
  241.                this.status = 7;
  242.                String var25 = propName + "notfound";
  243.                var25 = MessageUtils.subst(System.getProperty(var25), var1);
  244.                this.showAppletStatus(var25);
  245.                this.showAppletLog(var25);
  246.                this.showAppletException(var15);
  247.             } catch (InstantiationException var16) {
  248.                this.status = 7;
  249.                this.showAppletException(var16);
  250.                return;
  251.             } catch (IllegalAccessException var17) {
  252.                this.status = 7;
  253.                this.showAppletException(var17);
  254.                return;
  255.             } catch (Exception var18) {
  256.                this.status = 7;
  257.                String var24 = propName + "exception";
  258.                String var27 = ((Throwable)var18).getMessage();
  259.                this.showAppletStatus(MessageUtils.subst(System.getProperty(var24), var27));
  260.                this.showAppletException(var18);
  261.                return;
  262.             } catch (ThreadDeath var19) {
  263.                this.status = 7;
  264.                return;
  265.             } catch (Error var20) {
  266.                this.status = 7;
  267.                String var5 = propName + "error";
  268.                String var6 = ((Throwable)var20).getMessage();
  269.                this.showAppletStatus(MessageUtils.subst(System.getProperty(var5), var6));
  270.                this.showAppletException(var20);
  271.                return;
  272.             } finally {
  273.                ((Component)this).postEvent(new Event(this, 51236, (Object)null));
  274.             }
  275.  
  276.             return;
  277.          }
  278.  
  279.          Applet var23 = this.applet;
  280.          var23.stub = this;
  281.          this.applet.hide();
  282.          ((Container)this).add("Center", this.applet);
  283.          this.showAppletStatus(System.getProperty(propName + "loaded"));
  284.          ((Container)this).validate();
  285.       }
  286.    }
  287.  
  288.    protected synchronized void stopLoading() {
  289.       if (this.loaderThread != null) {
  290.          this.loaderThread.interrupt();
  291.       } else {
  292.          this.setLoadAbortRequest();
  293.       }
  294.    }
  295.  
  296.    protected synchronized boolean okToLoad() {
  297.       return !this.loadAbortRequest;
  298.    }
  299.  
  300.    protected synchronized void clearLoadAbortRequest() {
  301.       this.loadAbortRequest = false;
  302.    }
  303.  
  304.    protected synchronized void setLoadAbortRequest() {
  305.       this.loadAbortRequest = true;
  306.    }
  307.  
  308.    private synchronized void setLoaderThread(Thread var1) {
  309.       this.loaderThread = var1;
  310.    }
  311.  
  312.    public boolean isActive() {
  313.       return this.status == 3;
  314.    }
  315.  
  316.    public void appletResize(int var1, int var2) {
  317.    }
  318.  
  319.    public Applet getApplet() {
  320.       return this.applet;
  321.    }
  322.  
  323.    protected void showAppletStatus(String var1) {
  324.       String var2 = System.getProperty(var1);
  325.       if (var2 == null) {
  326.          var2 = var1;
  327.       }
  328.  
  329.       this.getAppletContext().showStatus(var2);
  330.    }
  331.  
  332.    protected void showAppletLog(String var1) {
  333.       String var2 = System.getProperty(var1);
  334.       if (var2 == null) {
  335.          var2 = var1;
  336.       }
  337.  
  338.       System.out.println(var2);
  339.    }
  340.  
  341.    protected void showAppletException(Throwable var1) {
  342.       var1.printStackTrace();
  343.       ((Component)this).repaint();
  344.    }
  345.  
  346.    synchronized AppletClassLoader getClassLoader(URL var1) throws IOException {
  347.       if (this.mAppletClassLoader == null) {
  348.          String var2 = var1.file;
  349.          if (var2.startsWith("/", var2.count - "/".count)) {
  350.             this.mAppletClassLoader = new AppletClassLoader(this.mAppletViewer, var1);
  351.          } else {
  352.             this.mAppletClassLoader = new AppletZipClassLoader(this.mAppletViewer, var1);
  353.          }
  354.       }
  355.  
  356.       return this.mAppletClassLoader;
  357.    }
  358.  
  359.    public abstract URL getDocumentBase();
  360.  
  361.    public abstract URL getCodeBase();
  362.  
  363.    public abstract String getParameter(String var1);
  364.  
  365.    public abstract AppletContext getAppletContext();
  366. }
  367.